package com.df.bpm.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.df.bpm.entity.CpFrequency;
import com.df.bpm.entity.CtrlPlanCpFrequency;
import com.df.bpm.service.impl.*;
import com.df.common.entity.Pagination;
import com.df.common.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 控制计划的频率控制器
 */
@Slf4j
@Tag(name = "控制计划的频率控制器")
@RequestMapping("/cpFrequency")
@RequiredArgsConstructor
@RestController
@SaCheckLogin
public class CpFrequencyController {
    private final CpFrequencyServiceImpl cpFrequencyServiceImpl;
    private final CtrlPlanCpFrequencyServiceImpl ctrlPlanCpFrequencyServiceImpl;

    /**
     * 查询控制频率
     * @param pagination 分页信息
     * @param temp 控制频率线索
     * @return  控制频率列表
     */
    @Operation(summary = "查询控制频率", description = "查询控制频率")
    @GetMapping("")
    @SaIgnore
    public ResponseEntity<?> getCpFrequency(Pagination pagination, CpFrequency temp) {
        if (CommonUtils.varIsNotBlank(pagination.getPageNum(), pagination.getPageSize())) {
            PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
            return ResponseEntity.ok(new PageInfo<>(cpFrequencyServiceImpl.getList4Like(temp)));
        } else {
            return ResponseEntity.ok(cpFrequencyServiceImpl.getList4Like(temp));
        }
    }

    /**
     * 新增控制频率
     * @param temp   控制频率信息
     * @return  新增成功后的控制频率信息
     */
    @Operation(summary = "新增控制频率", description = "新增控制频率")
    @PostMapping("")
    @SaIgnore
    public ResponseEntity<?> newCpFrequency(@RequestBody CpFrequency temp) {
        cpFrequencyServiceImpl.add(temp);
        return ResponseEntity.ok(temp);
    }

    /**
     * 控制频率关联控制计划
     * @param temp   关联关系
     * @return  关联关系
     */
    @Operation(summary = "关联控制计划", description = "关联控制计划")
    @PostMapping("bindCtrlPlan")
    @SaIgnore
    public ResponseEntity<?> bindCtrlPlan(@RequestBody CtrlPlanCpFrequency temp) {
        ctrlPlanCpFrequencyServiceImpl.add(temp);
        return ResponseEntity.ok(temp);
    }

}
